﻿using BricksProblemSolver.Solution1;
using BricksProblemSolver.Solution2;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BricksProblemSolver
{
    /*
     * 32x10 bricks solver
     */
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("Please input row length: ");
                var rowLength = int.Parse(Console.ReadLine());
                Console.Write("Please input row count: ");
                var height = int.Parse(Console.ReadLine());
                Console.Write("Please input brick types (example: 2,3): ");
                var types =
                    Console.ReadLine()
                    .Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => sbyte.Parse(x))
                    .ToArray();
                Console.WriteLine("Start solving L{0};H{1};T{2}", rowLength, height, string.Join(",", types));
                var solver = new Solver1(rowLength, height, types, new Log());
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var count = solver.SolveCount();
                stopWatch.Stop();
                Console.WriteLine("Got {0} results. Cost: {1:0.### (s)}", count, stopWatch.Elapsed.TotalSeconds);

                Console.Read();
                var result = solver.Solve();
                if (result.Any())
                {
                    Console.WriteLine("Print Result:");
                    for (var i = 0; i < result.LongCount(); ++i)
                    {
                        Console.WriteLine("Write {0}", i);
                        Console.WriteLine(result.ElementAt(i));
                    }
                    Console.Read();
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
                Console.Read();
            }
        }
    }
}
